<?php
/**
 * Created by PhpStorm.
 * User: PHP
 * Date: 2021/6/8
 * Time: 14:11
 */

namespace App\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;

class NoticeRequest extends FormRequest
{

    public function authorize()
    {
        return true;
    }


    //验证规则
    protected $rules = [
        'title' => 'required|between:3,20',
        'synopsis'=>'required',
        //'store_id'=>'required',

    ];


    public function messages() {
        return  [

            'title.required'=>'公告标题必须填写',
            'title.between'=>'公告标题必须在3到20位之间',
            'synopsis.required'=>'公告内容必须填写',
            //'store_id.required'=>'公告所属平台必须填写',
            'id.required' => '公告Id必须传递',
        ];

    }


    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = $this->rules;

        if (Request::getPathInfo() == '/adminapi/notice/update')//如果是login方法
        {
            $rules['id'] = 'required';
        }

        if (Request::getPathInfo() == '/adminapi/notice/del')//如果是login方法
        {
            $rules['id'] = 'required';
        }
        return $rules;

    }










}